using System;
using System.Globalization;
using System.IO;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Reflection;
using System.Security.Principal;
using MAPI;
using SharePoint.ImportExport.Core;
using Exchange.Export.DataHandler;
using ExchangeSiteParameters;
using System.Xml;
using System.Xml.Serialization;
using Exchange.Export.MHTMLHelper;

namespace Microsoft.SharePoint.Export.ExchangePublicFolders
{
    /// <summary>
    /// Summary description for frmExtractorMain.
    /// </summary>
    public class frmExtractorMain : System.Windows.Forms.Form
    {
        #region FormSpecificVariables
        private object vEmpty = Missing.Value;
        ExtensionsFrame extensionsFrame = new ExtensionsFrame();
        //		FoldersFrame foldersFrame = new FoldersFrame();
        private MAPI.Session oSession = new MAPI.Session();
        private helperFunctions oHelper = new helperFunctions();
        private string appPath = Application.StartupPath.ToString();
        private static ExchangeSiteParameters.SiteParameters siteParameters = new ExchangeSiteParameters.SiteParameters();
        private bool loggedOn = false;
        #endregion
        #region GeneralVariables
        private System.Windows.Forms.PictureBox pictureBox1;
        private System.Windows.Forms.TabControl tabControl1;
        private System.Windows.Forms.TabPage tabPage1;
        private System.Windows.Forms.Label lblExtractToFolder;
        private System.Windows.Forms.Label lblAlias;
        private System.Windows.Forms.Label lblServerName;
        private System.Windows.Forms.TextBox txtFolderToExtract;
        private System.Windows.Forms.TextBox txtAlias;
        private System.Windows.Forms.TextBox txtServerName;
        private System.Windows.Forms.Label label7;
        private System.Windows.Forms.TextBox txtStartFromFolder;
        private System.Windows.Forms.TabPage tabPage2;
        private System.Windows.Forms.TabPage tabPage3;
        private System.Windows.Forms.TextBox txtOwner;
        private System.Windows.Forms.Label lblOwner;
        private System.Windows.Forms.TextBox txtContact;
        private System.Windows.Forms.Label lblContact;
        private System.Windows.Forms.TextBox txtSiteOrAreaName;
        private System.Windows.Forms.Label lblNameOfArea;
        private System.Windows.Forms.TextBox txtRoot;
        private System.Windows.Forms.Label label3;
        private System.Windows.Forms.Button btnClose;
        private System.Windows.Forms.Button btnStart;
        private System.Windows.Forms.RichTextBox rtb_EventLog;
        private System.Windows.Forms.Button btnNext1;
        private System.Windows.Forms.Button button2;
        private System.Windows.Forms.Label label2;
        private System.Windows.Forms.TextBox txtExchangeStore;
        private System.Windows.Forms.CheckBox chkOnlyThisFolder;
        #endregion
        private System.Windows.Forms.ToolTip toolTip1;
        private System.Windows.Forms.Button btnSelectFolder;
        private System.Windows.Forms.CheckBox chkExportSecurity;
        private System.Windows.Forms.CheckBox chkAddWebPart;
        private System.Windows.Forms.Label label8;
        private System.Windows.Forms.Button btnPickPropertiesFile;
        private System.Windows.Forms.OpenFileDialog openFileDialog1;
        private System.Windows.Forms.TextBox txtXMLProperties;
        private System.Windows.Forms.TabPage tabPage4;
        private System.Windows.Forms.Button button3;
        private System.Windows.Forms.GroupBox groupBox2;
        private System.Windows.Forms.CheckBox chkUseDate;
        private System.Windows.Forms.DateTimePicker dateThreshHold;
        private System.Windows.Forms.Label label5;
        private System.Windows.Forms.ComboBox cmbConversation;
        private System.Windows.Forms.CheckBox chkAttachmentExtension;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.Label label4;
        private System.Windows.Forms.Label lblRestrictByDate;
        private System.Windows.Forms.TextBox txtRestrictBySize;
        private System.Windows.Forms.Label label6;
        private System.Windows.Forms.ComboBox cmbMailSaveType;
        private System.Windows.Forms.DateTimePicker endDateThreshHold;
        private System.Windows.Forms.Label lastSucceededDate;
        private System.Windows.Forms.Label lblEndTime;
        private System.Windows.Forms.Label lblStartTime;
        private System.ComponentModel.IContainer components;
        private System.Windows.Forms.TextBox txtInterval;
        private Button btnChooseTargetFolder;
        private FolderBrowserDialog folderBrowserDialog1;
        private System.Windows.Forms.Label lblInterval;

        /// <summary>
        /// 
        /// </summary>
        public frmExtractorMain()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();


        }
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.Run(new frmExtractorMain());
        }


        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frmExtractorMain));
            this.pictureBox1 = new System.Windows.Forms.PictureBox();
            this.tabControl1 = new System.Windows.Forms.TabControl();
            this.tabPage1 = new System.Windows.Forms.TabPage();
            this.chkAddWebPart = new System.Windows.Forms.CheckBox();
            this.chkExportSecurity = new System.Windows.Forms.CheckBox();
            this.btnChooseTargetFolder = new System.Windows.Forms.Button();
            this.btnSelectFolder = new System.Windows.Forms.Button();
            this.btnNext1 = new System.Windows.Forms.Button();
            this.lblExtractToFolder = new System.Windows.Forms.Label();
            this.lblAlias = new System.Windows.Forms.Label();
            this.lblServerName = new System.Windows.Forms.Label();
            this.txtFolderToExtract = new System.Windows.Forms.TextBox();
            this.txtAlias = new System.Windows.Forms.TextBox();
            this.txtServerName = new System.Windows.Forms.TextBox();
            this.label7 = new System.Windows.Forms.Label();
            this.txtStartFromFolder = new System.Windows.Forms.TextBox();
            this.label2 = new System.Windows.Forms.Label();
            this.txtExchangeStore = new System.Windows.Forms.TextBox();
            this.chkOnlyThisFolder = new System.Windows.Forms.CheckBox();
            this.txtXMLProperties = new System.Windows.Forms.TextBox();
            this.label8 = new System.Windows.Forms.Label();
            this.btnPickPropertiesFile = new System.Windows.Forms.Button();
            this.tabPage4 = new System.Windows.Forms.TabPage();
            this.groupBox2 = new System.Windows.Forms.GroupBox();
            this.lblInterval = new System.Windows.Forms.Label();
            this.txtInterval = new System.Windows.Forms.TextBox();
            this.lastSucceededDate = new System.Windows.Forms.Label();
            this.lblEndTime = new System.Windows.Forms.Label();
            this.lblStartTime = new System.Windows.Forms.Label();
            this.endDateThreshHold = new System.Windows.Forms.DateTimePicker();
            this.chkUseDate = new System.Windows.Forms.CheckBox();
            this.dateThreshHold = new System.Windows.Forms.DateTimePicker();
            this.label5 = new System.Windows.Forms.Label();
            this.cmbConversation = new System.Windows.Forms.ComboBox();
            this.chkAttachmentExtension = new System.Windows.Forms.CheckBox();
            this.label1 = new System.Windows.Forms.Label();
            this.label4 = new System.Windows.Forms.Label();
            this.lblRestrictByDate = new System.Windows.Forms.Label();
            this.txtRestrictBySize = new System.Windows.Forms.TextBox();
            this.label6 = new System.Windows.Forms.Label();
            this.cmbMailSaveType = new System.Windows.Forms.ComboBox();
            this.button3 = new System.Windows.Forms.Button();
            this.tabPage2 = new System.Windows.Forms.TabPage();
            this.button2 = new System.Windows.Forms.Button();
            this.txtOwner = new System.Windows.Forms.TextBox();
            this.lblOwner = new System.Windows.Forms.Label();
            this.txtContact = new System.Windows.Forms.TextBox();
            this.lblContact = new System.Windows.Forms.Label();
            this.txtSiteOrAreaName = new System.Windows.Forms.TextBox();
            this.lblNameOfArea = new System.Windows.Forms.Label();
            this.txtRoot = new System.Windows.Forms.TextBox();
            this.label3 = new System.Windows.Forms.Label();
            this.tabPage3 = new System.Windows.Forms.TabPage();
            this.btnClose = new System.Windows.Forms.Button();
            this.btnStart = new System.Windows.Forms.Button();
            this.rtb_EventLog = new System.Windows.Forms.RichTextBox();
            this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
            this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
            this.folderBrowserDialog1 = new System.Windows.Forms.FolderBrowserDialog();
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
            this.tabControl1.SuspendLayout();
            this.tabPage1.SuspendLayout();
            this.tabPage4.SuspendLayout();
            this.groupBox2.SuspendLayout();
            this.tabPage2.SuspendLayout();
            this.tabPage3.SuspendLayout();
            this.SuspendLayout();
            // 
            // pictureBox1
            // 
            this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
            this.pictureBox1.Location = new System.Drawing.Point(0, 0);
            this.pictureBox1.Name = "pictureBox1";
            this.pictureBox1.Size = new System.Drawing.Size(600, 72);
            this.pictureBox1.TabIndex = 0;
            this.pictureBox1.TabStop = false;
            // 
            // tabControl1
            // 
            this.tabControl1.Controls.Add(this.tabPage1);
            this.tabControl1.Controls.Add(this.tabPage4);
            this.tabControl1.Controls.Add(this.tabPage2);
            this.tabControl1.Controls.Add(this.tabPage3);
            this.tabControl1.Location = new System.Drawing.Point(0, 72);
            this.tabControl1.Name = "tabControl1";
            this.tabControl1.SelectedIndex = 0;
            this.tabControl1.Size = new System.Drawing.Size(600, 464);
            this.tabControl1.TabIndex = 0;
            // 
            // tabPage1
            // 
            this.tabPage1.Controls.Add(this.chkAddWebPart);
            this.tabPage1.Controls.Add(this.chkExportSecurity);
            this.tabPage1.Controls.Add(this.btnChooseTargetFolder);
            this.tabPage1.Controls.Add(this.btnSelectFolder);
            this.tabPage1.Controls.Add(this.btnNext1);
            this.tabPage1.Controls.Add(this.lblExtractToFolder);
            this.tabPage1.Controls.Add(this.lblAlias);
            this.tabPage1.Controls.Add(this.lblServerName);
            this.tabPage1.Controls.Add(this.txtFolderToExtract);
            this.tabPage1.Controls.Add(this.txtAlias);
            this.tabPage1.Controls.Add(this.txtServerName);
            this.tabPage1.Controls.Add(this.label7);
            this.tabPage1.Controls.Add(this.txtStartFromFolder);
            this.tabPage1.Controls.Add(this.label2);
            this.tabPage1.Controls.Add(this.txtExchangeStore);
            this.tabPage1.Controls.Add(this.chkOnlyThisFolder);
            this.tabPage1.Controls.Add(this.txtXMLProperties);
            this.tabPage1.Controls.Add(this.label8);
            this.tabPage1.Controls.Add(this.btnPickPropertiesFile);
            this.tabPage1.Location = new System.Drawing.Point(4, 22);
            this.tabPage1.Name = "tabPage1";
            this.tabPage1.Size = new System.Drawing.Size(592, 438);
            this.tabPage1.TabIndex = 0;
            this.tabPage1.Text = "Exchange Settings";
            // 
            // chkAddWebPart
            // 
            this.chkAddWebPart.Location = new System.Drawing.Point(437, 128);
            this.chkAddWebPart.Name = "chkAddWebPart";
            this.chkAddWebPart.Size = new System.Drawing.Size(104, 24);
            this.chkAddWebPart.TabIndex = 12;
            this.chkAddWebPart.Text = "Add Webpart";
            // 
            // chkExportSecurity
            // 
            this.chkExportSecurity.Location = new System.Drawing.Point(317, 128);
            this.chkExportSecurity.Name = "chkExportSecurity";
            this.chkExportSecurity.Size = new System.Drawing.Size(104, 24);
            this.chkExportSecurity.TabIndex = 11;
            this.chkExportSecurity.Text = "Export security";
            // 
            // btnChooseTargetFolder
            // 
            this.btnChooseTargetFolder.Location = new System.Drawing.Point(517, 66);
            this.btnChooseTargetFolder.Name = "btnChooseTargetFolder";
            this.btnChooseTargetFolder.Size = new System.Drawing.Size(24, 23);
            this.btnChooseTargetFolder.TabIndex = 6;
            this.btnChooseTargetFolder.Text = "+";
            this.btnChooseTargetFolder.Click += new System.EventHandler(this.btnChooseTargetFolder_Click);
            // 
            // btnSelectFolder
            // 
            this.btnSelectFolder.Location = new System.Drawing.Point(517, 96);
            this.btnSelectFolder.Name = "btnSelectFolder";
            this.btnSelectFolder.Size = new System.Drawing.Size(24, 23);
            this.btnSelectFolder.TabIndex = 9;
            this.btnSelectFolder.Text = "+";
            this.btnSelectFolder.Click += new System.EventHandler(this.btnSelectFolder_Click);
            // 
            // btnNext1
            // 
            this.btnNext1.BackColor = System.Drawing.SystemColors.HotTrack;
            this.btnNext1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btnNext1.ForeColor = System.Drawing.SystemColors.Menu;
            this.btnNext1.Location = new System.Drawing.Point(480, 408);
            this.btnNext1.Name = "btnNext1";
            this.btnNext1.Size = new System.Drawing.Size(96, 24);
            this.btnNext1.TabIndex = 18;
            this.btnNext1.Text = "&Next";
            this.btnNext1.UseVisualStyleBackColor = false;
            this.btnNext1.Click += new System.EventHandler(this.btnNext1_Click);
            // 
            // lblExtractToFolder
            // 
            this.lblExtractToFolder.Location = new System.Drawing.Point(8, 72);
            this.lblExtractToFolder.Name = "lblExtractToFolder";
            this.lblExtractToFolder.Size = new System.Drawing.Size(152, 23);
            this.lblExtractToFolder.TabIndex = 4;
            this.lblExtractToFolder.Text = "Target Folder:";
            // 
            // lblAlias
            // 
            this.lblAlias.Location = new System.Drawing.Point(8, 40);
            this.lblAlias.Name = "lblAlias";
            this.lblAlias.Size = new System.Drawing.Size(152, 23);
            this.lblAlias.TabIndex = 2;
            this.lblAlias.Text = "Exchange Alias:";
            // 
            // lblServerName
            // 
            this.lblServerName.Location = new System.Drawing.Point(8, 8);
            this.lblServerName.Name = "lblServerName";
            this.lblServerName.Size = new System.Drawing.Size(152, 23);
            this.lblServerName.TabIndex = 0;
            this.lblServerName.Text = "Exchange Server Name:";
            // 
            // txtFolderToExtract
            // 
            this.txtFolderToExtract.Location = new System.Drawing.Point(165, 66);
            this.txtFolderToExtract.Name = "txtFolderToExtract";
            this.txtFolderToExtract.Size = new System.Drawing.Size(336, 20);
            this.txtFolderToExtract.TabIndex = 5;
            // 
            // txtAlias
            // 
            this.txtAlias.Location = new System.Drawing.Point(165, 37);
            this.txtAlias.Name = "txtAlias";
            this.txtAlias.Size = new System.Drawing.Size(376, 20);
            this.txtAlias.TabIndex = 3;
            // 
            // txtServerName
            // 
            this.txtServerName.Location = new System.Drawing.Point(165, 8);
            this.txtServerName.Name = "txtServerName";
            this.txtServerName.Size = new System.Drawing.Size(376, 20);
            this.txtServerName.TabIndex = 1;
            // 
            // label7
            // 
            this.label7.Location = new System.Drawing.Point(8, 95);
            this.label7.Name = "label7";
            this.label7.Size = new System.Drawing.Size(152, 23);
            this.label7.TabIndex = 7;
            this.label7.Text = "Folder";
            // 
            // txtStartFromFolder
            // 
            this.txtStartFromFolder.Location = new System.Drawing.Point(165, 95);
            this.txtStartFromFolder.Name = "txtStartFromFolder";
            this.txtStartFromFolder.Size = new System.Drawing.Size(336, 20);
            this.txtStartFromFolder.TabIndex = 8;
            // 
            // label2
            // 
            this.label2.Location = new System.Drawing.Point(8, 160);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(152, 23);
            this.label2.TabIndex = 13;
            this.label2.Text = "Exchange Store";
            // 
            // txtExchangeStore
            // 
            this.txtExchangeStore.Location = new System.Drawing.Point(165, 160);
            this.txtExchangeStore.Name = "txtExchangeStore";
            this.txtExchangeStore.Size = new System.Drawing.Size(376, 20);
            this.txtExchangeStore.TabIndex = 14;
            this.txtExchangeStore.Text = "Public Folders";
            // 
            // chkOnlyThisFolder
            // 
            this.chkOnlyThisFolder.Location = new System.Drawing.Point(165, 128);
            this.chkOnlyThisFolder.Name = "chkOnlyThisFolder";
            this.chkOnlyThisFolder.Size = new System.Drawing.Size(136, 24);
            this.chkOnlyThisFolder.TabIndex = 10;
            this.chkOnlyThisFolder.Text = "Export only this folder";
            // 
            // txtXMLProperties
            // 
            this.txtXMLProperties.Location = new System.Drawing.Point(165, 192);
            this.txtXMLProperties.Name = "txtXMLProperties";
            this.txtXMLProperties.Size = new System.Drawing.Size(328, 20);
            this.txtXMLProperties.TabIndex = 16;
            this.txtXMLProperties.Text = "properties.xml";
            // 
            // label8
            // 
            this.label8.Location = new System.Drawing.Point(8, 192);
            this.label8.Name = "label8";
            this.label8.Size = new System.Drawing.Size(152, 23);
            this.label8.TabIndex = 15;
            this.label8.Text = "Property List";
            // 
            // btnPickPropertiesFile
            // 
            this.btnPickPropertiesFile.Location = new System.Drawing.Point(517, 192);
            this.btnPickPropertiesFile.Name = "btnPickPropertiesFile";
            this.btnPickPropertiesFile.Size = new System.Drawing.Size(24, 23);
            this.btnPickPropertiesFile.TabIndex = 17;
            this.btnPickPropertiesFile.Text = "+";
            this.btnPickPropertiesFile.Click += new System.EventHandler(this.btnPickPropertiesFile_Click);
            // 
            // tabPage4
            // 
            this.tabPage4.Controls.Add(this.groupBox2);
            this.tabPage4.Controls.Add(this.button3);
            this.tabPage4.Location = new System.Drawing.Point(4, 22);
            this.tabPage4.Name = "tabPage4";
            this.tabPage4.Size = new System.Drawing.Size(592, 438);
            this.tabPage4.TabIndex = 3;
            this.tabPage4.Text = "Message Settings";
            // 
            // groupBox2
            // 
            this.groupBox2.Controls.Add(this.lblInterval);
            this.groupBox2.Controls.Add(this.txtInterval);
            this.groupBox2.Controls.Add(this.lastSucceededDate);
            this.groupBox2.Controls.Add(this.lblEndTime);
            this.groupBox2.Controls.Add(this.lblStartTime);
            this.groupBox2.Controls.Add(this.endDateThreshHold);
            this.groupBox2.Controls.Add(this.chkUseDate);
            this.groupBox2.Controls.Add(this.dateThreshHold);
            this.groupBox2.Controls.Add(this.label5);
            this.groupBox2.Controls.Add(this.cmbConversation);
            this.groupBox2.Controls.Add(this.chkAttachmentExtension);
            this.groupBox2.Controls.Add(this.label1);
            this.groupBox2.Controls.Add(this.label4);
            this.groupBox2.Controls.Add(this.lblRestrictByDate);
            this.groupBox2.Controls.Add(this.txtRestrictBySize);
            this.groupBox2.Controls.Add(this.label6);
            this.groupBox2.Controls.Add(this.cmbMailSaveType);
            this.groupBox2.Location = new System.Drawing.Point(16, 16);
            this.groupBox2.Name = "groupBox2";
            this.groupBox2.Size = new System.Drawing.Size(456, 344);
            this.groupBox2.TabIndex = 20;
            this.groupBox2.TabStop = false;
            this.groupBox2.Text = "Message Settings";
            // 
            // lblInterval
            // 
            this.lblInterval.Location = new System.Drawing.Point(144, 256);
            this.lblInterval.Name = "lblInterval";
            this.lblInterval.Size = new System.Drawing.Size(64, 23);
            this.lblInterval.TabIndex = 16;
            this.lblInterval.Text = "Interval";
            this.lblInterval.Visible = false;
            // 
            // txtInterval
            // 
            this.txtInterval.Location = new System.Drawing.Point(216, 256);
            this.txtInterval.Name = "txtInterval";
            this.txtInterval.Size = new System.Drawing.Size(32, 20);
            this.txtInterval.TabIndex = 15;
            this.txtInterval.Visible = false;
            // 
            // lastSucceededDate
            // 
            this.lastSucceededDate.Location = new System.Drawing.Point(216, 304);
            this.lastSucceededDate.Name = "lastSucceededDate";
            this.lastSucceededDate.Size = new System.Drawing.Size(100, 23);
            this.lastSucceededDate.TabIndex = 14;
            this.lastSucceededDate.Visible = false;
            // 
            // lblEndTime
            // 
            this.lblEndTime.Location = new System.Drawing.Point(144, 224);
            this.lblEndTime.Name = "lblEndTime";
            this.lblEndTime.Size = new System.Drawing.Size(64, 23);
            this.lblEndTime.TabIndex = 13;
            this.lblEndTime.Text = "End Time:";
            this.lblEndTime.Visible = false;
            // 
            // lblStartTime
            // 
            this.lblStartTime.Location = new System.Drawing.Point(144, 192);
            this.lblStartTime.Name = "lblStartTime";
            this.lblStartTime.Size = new System.Drawing.Size(64, 23);
            this.lblStartTime.TabIndex = 12;
            this.lblStartTime.Text = "Start Time:";
            this.lblStartTime.Visible = false;
            // 
            // endDateThreshHold
            // 
            this.endDateThreshHold.CustomFormat = "yyyy/MM/dd hh:mm:ss";
            this.endDateThreshHold.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
            this.endDateThreshHold.Location = new System.Drawing.Point(216, 224);
            this.endDateThreshHold.Name = "endDateThreshHold";
            this.endDateThreshHold.Size = new System.Drawing.Size(168, 20);
            this.endDateThreshHold.TabIndex = 11;
            this.endDateThreshHold.Visible = false;
            // 
            // chkUseDate
            // 
            this.chkUseDate.Location = new System.Drawing.Point(216, 152);
            this.chkUseDate.Name = "chkUseDate";
            this.chkUseDate.Size = new System.Drawing.Size(24, 24);
            this.chkUseDate.TabIndex = 1;
            this.chkUseDate.CheckedChanged += new System.EventHandler(this.chkUseDate_CheckedChanged);
            // 
            // dateThreshHold
            // 
            this.dateThreshHold.CustomFormat = "yyyy/MM/dd hh:mm:ss";
            this.dateThreshHold.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
            this.dateThreshHold.Location = new System.Drawing.Point(216, 192);
            this.dateThreshHold.Name = "dateThreshHold";
            this.dateThreshHold.Size = new System.Drawing.Size(168, 20);
            this.dateThreshHold.TabIndex = 2;
            this.dateThreshHold.Visible = false;
            // 
            // label5
            // 
            this.label5.Location = new System.Drawing.Point(8, 120);
            this.label5.Name = "label5";
            this.label5.Size = new System.Drawing.Size(192, 23);
            this.label5.TabIndex = 10;
            this.label5.Text = "Discussion Type:";
            // 
            // cmbConversation
            // 
            this.cmbConversation.Items.AddRange(new object[] {
            "Discussion",
            "Mail"});
            this.cmbConversation.Location = new System.Drawing.Point(216, 120);
            this.cmbConversation.Name = "cmbConversation";
            this.cmbConversation.Size = new System.Drawing.Size(200, 21);
            this.cmbConversation.TabIndex = 0;
            // 
            // chkAttachmentExtension
            // 
            this.chkAttachmentExtension.Location = new System.Drawing.Point(216, 24);
            this.chkAttachmentExtension.Name = "chkAttachmentExtension";
            this.chkAttachmentExtension.Size = new System.Drawing.Size(16, 21);
            this.chkAttachmentExtension.TabIndex = 5;
            // 
            // label1
            // 
            this.label1.Location = new System.Drawing.Point(8, 24);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(192, 23);
            this.label1.TabIndex = 3;
            this.label1.Text = "Restrict by Attachment extension:";
            // 
            // label4
            // 
            this.label4.Location = new System.Drawing.Point(8, 56);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(192, 23);
            this.label4.TabIndex = 6;
            this.label4.Text = "Restrict by Size (KB):";
            // 
            // lblRestrictByDate
            // 
            this.lblRestrictByDate.Location = new System.Drawing.Point(8, 152);
            this.lblRestrictByDate.Name = "lblRestrictByDate";
            this.lblRestrictByDate.Size = new System.Drawing.Size(192, 23);
            this.lblRestrictByDate.TabIndex = 0;
            this.lblRestrictByDate.Text = "Restrict by date:";
            // 
            // txtRestrictBySize
            // 
            this.txtRestrictBySize.Location = new System.Drawing.Point(216, 56);
            this.txtRestrictBySize.Name = "txtRestrictBySize";
            this.txtRestrictBySize.Size = new System.Drawing.Size(200, 20);
            this.txtRestrictBySize.TabIndex = 7;
            // 
            // label6
            // 
            this.label6.Location = new System.Drawing.Point(8, 88);
            this.label6.Name = "label6";
            this.label6.Size = new System.Drawing.Size(192, 23);
            this.label6.TabIndex = 8;
            this.label6.Text = "Save mail message as:";
            // 
            // cmbMailSaveType
            // 
            this.cmbMailSaveType.Items.AddRange(new object[] {
            "RTF-File",
            "TXT-File",
            "HTM-FILE",
            "MSG-File",
            "Attachment as message"});
            this.cmbMailSaveType.Location = new System.Drawing.Point(216, 88);
            this.cmbMailSaveType.Name = "cmbMailSaveType";
            this.cmbMailSaveType.Size = new System.Drawing.Size(200, 21);
            this.cmbMailSaveType.TabIndex = 9;
            // 
            // button3
            // 
            this.button3.BackColor = System.Drawing.SystemColors.HotTrack;
            this.button3.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.button3.ForeColor = System.Drawing.SystemColors.Menu;
            this.button3.Location = new System.Drawing.Point(480, 408);
            this.button3.Name = "button3";
            this.button3.Size = new System.Drawing.Size(96, 24);
            this.button3.TabIndex = 19;
            this.button3.Text = "&Next";
            this.button3.UseVisualStyleBackColor = false;
            this.button3.Click += new System.EventHandler(this.button3_Click);
            // 
            // tabPage2
            // 
            this.tabPage2.Controls.Add(this.button2);
            this.tabPage2.Controls.Add(this.txtOwner);
            this.tabPage2.Controls.Add(this.lblOwner);
            this.tabPage2.Controls.Add(this.txtContact);
            this.tabPage2.Controls.Add(this.lblContact);
            this.tabPage2.Controls.Add(this.txtSiteOrAreaName);
            this.tabPage2.Controls.Add(this.lblNameOfArea);
            this.tabPage2.Controls.Add(this.txtRoot);
            this.tabPage2.Controls.Add(this.label3);
            this.tabPage2.Location = new System.Drawing.Point(4, 22);
            this.tabPage2.Name = "tabPage2";
            this.tabPage2.Size = new System.Drawing.Size(592, 438);
            this.tabPage2.TabIndex = 1;
            this.tabPage2.Text = "SharePoint Settings";
            // 
            // button2
            // 
            this.button2.BackColor = System.Drawing.SystemColors.HotTrack;
            this.button2.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.button2.ForeColor = System.Drawing.SystemColors.Menu;
            this.button2.Location = new System.Drawing.Point(480, 408);
            this.button2.Name = "button2";
            this.button2.Size = new System.Drawing.Size(96, 24);
            this.button2.TabIndex = 10;
            this.button2.Text = "N&ext";
            this.button2.UseVisualStyleBackColor = false;
            this.button2.Click += new System.EventHandler(this.button2_Click);
            // 
            // txtOwner
            // 
            this.txtOwner.Location = new System.Drawing.Point(216, 168);
            this.txtOwner.Name = "txtOwner";
            this.txtOwner.Size = new System.Drawing.Size(256, 20);
            this.txtOwner.TabIndex = 9;
            // 
            // lblOwner
            // 
            this.lblOwner.Location = new System.Drawing.Point(8, 168);
            this.lblOwner.Name = "lblOwner";
            this.lblOwner.Size = new System.Drawing.Size(192, 23);
            this.lblOwner.TabIndex = 8;
            this.lblOwner.Text = "Owner Domain Account:";
            // 
            // txtContact
            // 
            this.txtContact.Location = new System.Drawing.Point(216, 128);
            this.txtContact.Name = "txtContact";
            this.txtContact.Size = new System.Drawing.Size(256, 20);
            this.txtContact.TabIndex = 7;
            // 
            // lblContact
            // 
            this.lblContact.Location = new System.Drawing.Point(8, 128);
            this.lblContact.Name = "lblContact";
            this.lblContact.Size = new System.Drawing.Size(192, 23);
            this.lblContact.TabIndex = 6;
            this.lblContact.Text = "Contact eMail:";
            // 
            // txtSiteOrAreaName
            // 
            this.txtSiteOrAreaName.Location = new System.Drawing.Point(216, 88);
            this.txtSiteOrAreaName.Name = "txtSiteOrAreaName";
            this.txtSiteOrAreaName.Size = new System.Drawing.Size(256, 20);
            this.txtSiteOrAreaName.TabIndex = 5;
            // 
            // lblNameOfArea
            // 
            this.lblNameOfArea.Location = new System.Drawing.Point(8, 86);
            this.lblNameOfArea.Name = "lblNameOfArea";
            this.lblNameOfArea.Size = new System.Drawing.Size(192, 23);
            this.lblNameOfArea.TabIndex = 4;
            this.lblNameOfArea.Text = "Name:";
            // 
            // txtRoot
            // 
            this.txtRoot.Location = new System.Drawing.Point(216, 13);
            this.txtRoot.Name = "txtRoot";
            this.txtRoot.Size = new System.Drawing.Size(256, 20);
            this.txtRoot.TabIndex = 3;
            // 
            // label3
            // 
            this.label3.Location = new System.Drawing.Point(8, 12);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(192, 23);
            this.label3.TabIndex = 2;
            this.label3.Text = "Managed Path:";
            this.label3.Click += new System.EventHandler(this.label3_Click);
            // 
            // tabPage3
            // 
            this.tabPage3.Controls.Add(this.btnClose);
            this.tabPage3.Controls.Add(this.btnStart);
            this.tabPage3.Controls.Add(this.rtb_EventLog);
            this.tabPage3.Location = new System.Drawing.Point(4, 22);
            this.tabPage3.Name = "tabPage3";
            this.tabPage3.Size = new System.Drawing.Size(592, 438);
            this.tabPage3.TabIndex = 2;
            this.tabPage3.Text = "Export";
            // 
            // btnClose
            // 
            this.btnClose.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
            this.btnClose.BackColor = System.Drawing.SystemColors.HotTrack;
            this.btnClose.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btnClose.ForeColor = System.Drawing.SystemColors.Info;
            this.btnClose.Location = new System.Drawing.Point(8, 408);
            this.btnClose.Name = "btnClose";
            this.btnClose.Size = new System.Drawing.Size(96, 24);
            this.btnClose.TabIndex = 19;
            this.btnClose.Text = "Close";
            this.btnClose.UseVisualStyleBackColor = false;
            this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
            // 
            // btnStart
            // 
            this.btnStart.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
            this.btnStart.BackColor = System.Drawing.SystemColors.HotTrack;
            this.btnStart.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btnStart.ForeColor = System.Drawing.SystemColors.Menu;
            this.btnStart.Location = new System.Drawing.Point(480, 408);
            this.btnStart.Name = "btnStart";
            this.btnStart.Size = new System.Drawing.Size(96, 24);
            this.btnStart.TabIndex = 18;
            this.btnStart.Text = "&Start Export";
            this.btnStart.UseVisualStyleBackColor = false;
            this.btnStart.Click += new System.EventHandler(this.btnStart_Click);
            // 
            // rtb_EventLog
            // 
            this.rtb_EventLog.BorderStyle = System.Windows.Forms.BorderStyle.None;
            this.rtb_EventLog.Location = new System.Drawing.Point(8, 8);
            this.rtb_EventLog.Name = "rtb_EventLog";
            this.rtb_EventLog.Size = new System.Drawing.Size(576, 392);
            this.rtb_EventLog.TabIndex = 4;
            this.rtb_EventLog.Text = "Waiting...";
            // 
            // toolTip1
            // 
            this.toolTip1.ShowAlways = true;
            // 
            // frmExtractorMain
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(600, 550);
            this.Controls.Add(this.tabControl1);
            this.Controls.Add(this.pictureBox1);
            this.Name = "frmExtractorMain";
            this.Text = "Exchange Public Folder Extractor";
            this.Load += new System.EventHandler(this.frmExtractorMain_Load);
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
            this.tabControl1.ResumeLayout(false);
            this.tabPage1.ResumeLayout(false);
            this.tabPage1.PerformLayout();
            this.tabPage4.ResumeLayout(false);
            this.groupBox2.ResumeLayout(false);
            this.groupBox2.PerformLayout();
            this.tabPage2.ResumeLayout(false);
            this.tabPage2.PerformLayout();
            this.tabPage3.ResumeLayout(false);
            this.ResumeLayout(false);

        }
        #endregion

        private void btnClose_Click(object sender, System.EventArgs e)
        {
            DialogResult result = MessageBox.Show("Are you sure you'd like to exit?", "Close Application", MessageBoxButtons.YesNo);
            if (result == DialogResult.Yes)
            {
                try
                {
                    string filename = Application.StartupPath + "\\config.xml";
                    siteParameters.Serialize(filename);
                }
                catch
                {
                }

                this.Close();
            }
        }
        private bool Logon()
        {
            if (loggedOn) //Already logged on
                return true;
            bool bRetValue = false;
            string sProfileInfo = "";
            try
            {
                sProfileInfo = txtServerName.Text + "\n" + txtAlias.Text;
                if (null == oSession)
                    oSession = new MAPI.Session();
                if (sProfileInfo.Trim().Length > 1)
                    oSession.Logon(vEmpty, vEmpty, true, true, 0, true, sProfileInfo);
                else
                    oSession.Logon(vEmpty, vEmpty, true, true, 0, true, vEmpty);
                loggedOn = true;
                bRetValue = true;
                Logger.Log(ErrorLevel.Information, "Logged on to mailbox " + sProfileInfo);

                //Kimmo changed
            }
            catch (System.Runtime.InteropServices.COMException Ex)
            {
                Logger.Log(ErrorLevel.Error, "Could not logon to mailbox " + sProfileInfo + ". Error: " + Ex.Message);
                loggedOn = false;
            }
            return bRetValue;
        }

        private void btnStart_Click(object sender, System.EventArgs e)
        {
            rtb_EventLog.Clear();
            Logger.Init("Export" + DateTime.Now.ToString("MMddHHmm") + ".log", ErrorLevel.Information);
            Logger.LogDataSendingEvent += new Logger.LogDataEventHandler(this.IncomingEventLogData);

            if (!Logon())
            {
                Logger.Log(ErrorLevel.Error, "Could not logon");
                Logger.LogDataSendingEvent -= new Logger.LogDataEventHandler(this.IncomingEventLogData);
                return;
            }

            if (-1 == cmbConversation.SelectedIndex)
            {
                MessageBox.Show("Please select whether a folder will be exported as a threaded discussion or as a document library");
                cmbConversation.Focus();
                Logger.LogDataSendingEvent -= new Logger.LogDataEventHandler(this.IncomingEventLogData);
                return;
            }
            if (txtSiteOrAreaName.Text.Trim().Length == 0)
            {
                MessageBox.Show("A Site/Area name must be specified");
                txtSiteOrAreaName.Focus();
                Logger.LogDataSendingEvent -= new Logger.LogDataEventHandler(this.IncomingEventLogData);
                return;
            }
            if (txtFolderToExtract.Text.Trim().Length == 0)
            {
                MessageBox.Show("A target folder must be specified");
                txtFolderToExtract.Focus();
                Logger.LogDataSendingEvent -= new Logger.LogDataEventHandler(this.IncomingEventLogData);
                return;
            }
            if (!File.Exists(txtXMLProperties.Text))
            {
                MessageBox.Show("The propertylist file must be specified");
                txtXMLProperties.Focus();
                Logger.LogDataSendingEvent -= new Logger.LogDataEventHandler(this.IncomingEventLogData);
                return;
            }

            ArrayList extensions = new ArrayList();
            ArrayList folders = new ArrayList();
            string restrictBySize = "";
            /*				if (chkAttachmentExtension.Checked==true)
                    {
                        extensions  = getAttachmentExtensions();
                        foreach(object exten in extensions)
                        {
                            MessageBox.Show(exten.ToString());
                        }
                    }
                    if (bfolderSelected)
                    {
                        folders = getFoldersToFind();
                        foreach(object mapiFolder in folders)
                        {
                            MessageBox.Show(mapiFolder.ToString());
                        }
                    }
            */
            if (txtRestrictBySize.Text.Trim() != "")
            {
                restrictBySize = txtRestrictBySize.Text;
            }
            Parameter parameter = null;
            if (siteParameters.List.Count == 0)
            {
                parameter = new Parameter();
                siteParameters.List.Add(parameter);
            }
            else
                parameter = siteParameters.List[0];


            parameter.ContainerType = "Site";
            parameter.ManagedPath = txtRoot.Text.ToString();
            parameter.SiteName = txtSiteOrAreaName.Text.ToString();
            parameter.Owner = txtOwner.Text.ToString();
            parameter.Contact = txtContact.Text.ToString();
            parameter.conversation = cmbConversation.SelectedItem.ToString();
            parameter.store = txtExchangeStore.Text;
            parameter.exportSecurity = chkExportSecurity.Checked.ToString();
            parameter.addWebPart = chkAddWebPart.Checked.ToString();

            parameter.ServerName = txtServerName.Text;
            parameter.Alias = txtAlias.Text;
            parameter.FolderToExtract = txtFolderToExtract.Text;
            parameter.StartFromFolder = txtStartFromFolder.Text;
            parameter.RestrictBySize = txtRestrictBySize.Text;
            parameter.MailSaveType = cmbMailSaveType.Text;
            parameter.Root = txtRoot.Text;
            parameter.ContainerTypeIndex = cmbConversation.SelectedIndex.ToString();
            parameter.ContainerTypeIndex = "0";
            parameter.XMLProps = txtXMLProperties.Text;
            parameter.Interval = txtInterval.Text;
            parameter.MailSaveType = cmbMailSaveType.Text;

            //getMessages();
            Exporter oExporter = new Exporter(cmbMailSaveType.Text, txtStartFromFolder.Text);
            oExporter.oSession = oSession;

            string path = oHelper.createFolder(txtFolderToExtract.Text);
            bool onlyTopFolder = false;
            if (chkOnlyThisFolder.Checked)
                onlyTopFolder = true;
            parameter.onlyTopFolder = onlyTopFolder.ToString();

            Logger.Log(ErrorLevel.Information, "Created folder " + txtFolderToExtract.Text);
            DateTime dateTimeThreshHold = DateTime.MinValue;
            DateTime dateTimeEndValue = DateTime.MinValue;
            if (chkUseDate.Checked)
            {
                dateTimeThreshHold = dateThreshHold.Value;
                dateTimeEndValue = endDateThreshHold.Value;
                parameter.dateTimeThreshHold = dateTimeThreshHold.ToString();
                parameter.dateTimeEnd = dateTimeEndValue.ToString();
                parameter.Interval = txtInterval.Text.ToString();

            }
            else
            {
                parameter.dateTimeThreshHold = dateTimeThreshHold.ToString();
                parameter.dateTimeEnd = dateTimeEndValue.ToString();
                parameter.Interval = "0";
                
            }

            //siteParameters.List.Add(parameter); 
            oExporter.getMessages(folders, extensions, restrictBySize, dateTimeThreshHold, path, onlyTopFolder, parameter.dateTimeEnd, ref parameter);
            try
            {
                oSession.Logoff();
                System.Runtime.InteropServices.Marshal.ReleaseComObject(oSession);
                oSession = null;

                loggedOn = false;
            }
            catch (Exception LogoffEx)
            {
                Logger.Log(ErrorLevel.Error, "Error logging off: " + LogoffEx.Message);
            }

            Logger.Log(ErrorLevel.Progress, "All Done!");
            Logger.LogDataSendingEvent -= new Logger.LogDataEventHandler(this.IncomingEventLogData);
            Directory.SetCurrentDirectory(Application.StartupPath);
            btnClose.Focus();


            return;

        }

        private void btnNext1_Click(object sender, System.EventArgs e)
        {
            tabControl1.SelectedIndex = 1;

        }

        private void button2_Click(object sender, System.EventArgs e)
        {
            tabControl1.SelectedIndex = 3;
        }

        private void lineFormatter(ErrorLevel level)
        {
            System.Drawing.Font currentFont = rtb_EventLog.SelectionFont;
            System.Drawing.FontStyle newFontStyle;

            switch (level)
            {
                case ErrorLevel.Error: // critical
                    newFontStyle = FontStyle.Bold;
                    rtb_EventLog.SelectionColor = Color.Red;
                    break;
                case ErrorLevel.Warning:  // warning
                    newFontStyle = FontStyle.Regular;
                    rtb_EventLog.SelectionColor = Color.Red;
                    break;
                    break;
                default:
                    rtb_EventLog.SelectionColor = Color.Black;
                    newFontStyle = FontStyle.Regular;
                    break;
                // regular output
            }

            rtb_EventLog.SelectionFont = new Font(
            currentFont.FontFamily,
            currentFont.Size,
            newFontStyle);

        }

        /// <summary>
        /// RichTextBox Event Logger component
        /// </summary>
        public void addTextToLogRtf(string IncomingLogData)
        {
            try
            {
                string sLevel = IncomingLogData.Substring(0, IncomingLogData.IndexOf("-"));
                ErrorLevel level = (ErrorLevel)Enum.Parse(typeof(ErrorLevel), sLevel);
                lineFormatter(level);
                IncomingLogData = DateTime.Now.ToLongTimeString() + ":  " + IncomingLogData.Substring( IncomingLogData.IndexOf("-")+1) + "\n";

                //NOTE: replace rtf_eventlog with your RTF window, or text window, in your window app, to display log info.
                rtb_EventLog.AppendText(IncomingLogData);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("error while trying to write events incoming to AddTextToLogRtf function, error:" + ex.Message + ", in location:" + ex.TargetSite);
            }
            finally
            {
            }
        }
        private void IncomingEventLogData(object sender, SPEventArgs e)
        {
            try
            {
                addTextToLogRtf(e.Message);
            }
            catch (Exception ex)
            {
                string errorString = "Error in trying to find AD presence, error:" + ex.Message + ", in module:" + ex.TargetSite;
                addTextToLogRtf(errorString);
                System.Diagnostics.Debug.WriteLine(errorString);
            }
            finally
            {
            }
        }

        private void frmExtractorMain_Load(object sender, System.EventArgs e)
        {

            // Set up the delays for the ToolTip.
            toolTip1.AutoPopDelay = 5000;
            toolTip1.InitialDelay = 1000;
            toolTip1.ReshowDelay = 500;
            // Force the ToolTip text to be displayed whether or not the form is active.
            toolTip1.ShowAlways = true;


            toolTip1.SetToolTip(this.txtAlias, "This specifies the email address of MAPI Profile");
            toolTip1.SetToolTip(this.txtServerName, "This is the name of the Exchnage server that the MAPI profile connects to");
            toolTip1.SetToolTip(this.txtSiteOrAreaName, "This specifies the starting point of the data migration");
            toolTip1.SetToolTip(this.txtExchangeStore, "This specifies store in the Exchange servers that MAPI connects to");
            toolTip1.SetToolTip(this.txtStartFromFolder, "This specifies folder that is start path");

            WindowsPrincipal wp = new WindowsPrincipal(WindowsIdentity.GetCurrent());
            int nPos = wp.Identity.Name.LastIndexOf("\\");

            txtAlias.Text = wp.Identity.Name.Substring(nPos + 1, wp.Identity.Name.Length - nPos - 1);
            txtServerName.Text = System.Environment.MachineName;
            txtOwner.Text = wp.Identity.Name.ToString();

            DateTime dt = DateTime.Now;
            DateTimeFormatInfo s = System.Threading.Thread.CurrentThread.CurrentUICulture.DateTimeFormat;
            dateThreshHold.CustomFormat = s.ShortDatePattern + " " + s.ShortTimePattern;

            endDateThreshHold.CustomFormat = s.ShortDatePattern + " " + s.ShortTimePattern;



            try
            {
                //this config parameter has to be implemented to form...
                string dir = Assembly.GetEntryAssembly().Location;
                int pos = dir.LastIndexOf("\\");
                dir = dir.Substring(0, pos);

                string fileName = dir + "\\config.xml";

                setSiteParamters(fileName);
                Parameter parameter = siteParameters.List[0];
                txtRoot.Text = parameter.ManagedPath;
                txtSiteOrAreaName.Text = parameter.SiteName;
                txtOwner.Text = parameter.Owner;
                txtContact.Text = parameter.Contact;
                cmbConversation.Text = parameter.conversation;
                txtExchangeStore.Text = parameter.store;
                chkExportSecurity.Checked = bool.Parse(parameter.exportSecurity);
                txtInterval.Text = parameter.Interval;
                chkAddWebPart.Checked = bool.Parse(parameter.addWebPart);
                DateTime threshHold = DateTime.Parse(parameter.dateTimeThreshHold);
                chkOnlyThisFolder.Checked = bool.Parse(parameter.onlyTopFolder);
                if (threshHold != DateTime.MinValue)
                {
                    chkUseDate.Checked = true;
                    dateThreshHold.Value = threshHold;
                }
                if (parameter.dateTimeEnd != "")
                {
                    DateTime endThreshHold = DateTime.Parse(parameter.dateTimeEnd);
                    if (endThreshHold != DateTime.MinValue)
                    {
                        endDateThreshHold.Value = endThreshHold;
                    }
                }
                string ss = parameter.LastSucceededDate;
                lastSucceededDate.Text = ss;
                txtServerName.Text = parameter.ServerName;
                txtAlias.Text = parameter.Alias;
                txtFolderToExtract.Text = parameter.FolderToExtract;
                txtStartFromFolder.Text = parameter.StartFromFolder;
                txtRestrictBySize.Text = parameter.RestrictBySize;
                cmbMailSaveType.Text = parameter.MailSaveType;
                txtRoot.Text = parameter.Root;
                cmbConversation.SelectedIndex = int.Parse(parameter.ConversationIndex);
                txtXMLProperties.Text = parameter.XMLProps;
                chkOnlyThisFolder.Checked = bool.Parse(parameter.onlyTopFolder);



            }
            catch
            {
            }
            if (txtXMLProperties.Text.Length < 15)
            {

                string dir = Assembly.GetEntryAssembly().Location;
                int pos = dir.LastIndexOf("\\");
                dir = dir.Substring(0, pos);

                txtXMLProperties.Text = dir + "\\properties.xml";
            }

        }
        private static bool setSiteParamters(string fileName)
        {
            try
            {
                FileStream fs = new FileStream(fileName, FileMode.Open);
                XmlReader reader = new XmlTextReader(fs);
                XmlSerializer serializer = new XmlSerializer(typeof(ExchangeSiteParameters.SiteParameters));

                siteParameters = (ExchangeSiteParameters.SiteParameters)serializer.Deserialize(reader);
                fs.Close();
                return (true);
            }
            catch (Exception ex)
            {
                Logger.Log(ErrorLevel.Error, "Could not find siteParametrs file " + fileName + ". Error: " + ex.Message);
                return (false);
            }

        }

        private void chkUseDate_CheckedChanged(object sender, System.EventArgs e)
        {
            if (chkUseDate.Checked)
            {
                dateThreshHold.Visible = true;
                endDateThreshHold.Visible = true;

                lastSucceededDate.Visible = true;
                lblEndTime.Visible = true;
                lblStartTime.Visible = true;
                lblInterval.Visible = true;
                txtInterval.Visible = true;
            }
            else
            {
                dateThreshHold.Visible = false;
                endDateThreshHold.Visible = false;
                lastSucceededDate.Visible = false;
                lblEndTime.Visible = false;
                lblStartTime.Visible = false;
                lblInterval.Visible = false;
                txtInterval.Visible = false;
            }
        }

        private void btnSelectFolder_Click(object sender, System.EventArgs e)
        {
            if (Logon())
            {
                folderPicker picker = new folderPicker(txtStartFromFolder.Text, txtExchangeStore.Text, oSession);
                DialogResult result = picker.ShowDialog(this);
                if (result == DialogResult.OK)
                    txtStartFromFolder.Text = picker.SelectedFolder;


            }
        }

        private void btnPickPropertiesFile_Click(object sender, System.EventArgs e)
        {
            openFileDialog1.DefaultExt = "xml";
            openFileDialog1.RestoreDirectory = true;
            openFileDialog1.Title = "Choose the properties xml file";
            openFileDialog1.Multiselect = false;
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                txtXMLProperties.Text = openFileDialog1.FileName;
            }

        }

        private void button3_Click(object sender, System.EventArgs e)
        {
            tabControl1.SelectedIndex = 2;
        }

        private void btnChooseTargetFolder_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1.ShowNewFolderButton = true;

            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                txtFolderToExtract.Text = folderBrowserDialog1.SelectedPath;
            }
        }

        private void label3_Click(object sender, EventArgs e)
        {

        }



    }
}
